package com.etc.sortdemo;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author: knowno
 * @create: 2024-09-11 13:43
 * @Version 1.0
 **/
public class CollectionsSort {
    public static void main(String[] args) {

        List<Integer> list = Arrays.asList(1,3,5,7,9,8,6,4,2,0,100);

        //方法
        Collections.sort(list);

        //排序后的输出
        System.out.println(list);

        System.out.println("**********************");
        //如果提供的是字符串，默认按照字符来比较的.
        List<String> list1 = Arrays.asList("hello","Hello","helo","Java","12","2");

        //方法
        Collections.sort(list1);

        //排序后的输出
        System.out.println(list1);

        System.out.println("**********************");
        //如果提供的是字符串，默认按照字符来比较的.
        List<String> list2= Arrays.asList("2","123","22","9","12","2");

//        Collections.sort(list2);

        //方法
        Collections.sort(list2, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.parseInt(o1)-Integer.parseInt(o2);
            }
        });

        //排序后的输出
        System.out.println(list2);

    }
}
